package com.zhuzhe.blog.article.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhuzhe.blog.article.requestDto.ArticleListDto;
import com.zhuzhe.blog.article.requestDto.ArticleSerachDto;
import com.zhuzhe.blog.article.responseVo.ArticlePageListVo;
import com.zhuzhe.blog.article.responseVo.ArticleVo;
import com.zhuzhe.blog.article.service.IArticleService;
import com.zhuzhe.blog.base.ResponseData;
import com.zhuzhe.blog.article.entity.Article;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @description
 * @author: u53
 * @create: 2020-09-29 14:53
 **/

@Api(value="分类管理接口", description = "无需通过身份验证即可访问接口")
@RequestMapping("/api/article")
@RestController
public class ApiArticleController {

    @Autowired
    private IArticleService articleService;


    @ApiOperation("根据id查询文章详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "文章id" ,required = true),
            @ApiImplicitParam(name = "userId",value = "用户id" ,required = false)
    })
    @GetMapping("/{id}")
    public ResponseData<ArticleVo>searchById(@PathVariable String id , String userId) {
        return articleService.findArticleAndLabelById(id,userId);
    }

    @ApiImplicitParam(name = "id", value = "文章ID", required = true)
    @ApiOperation("更新文章浏览次数")
    @PutMapping("/viewCount/{id}") // /api/article/viewCount/{id}
    public ResponseData<String> updateViewCount(@PathVariable("id") String id, HttpServletRequest request) {
        return articleService.updateViewCount(id,request);
    }

    @ApiOperation("公开且已审核的文章列表接口")
    @PostMapping("/list") // /api/article/list
    public ResponseData<IPage<ArticlePageListVo> > list(@RequestBody ArticleListDto articleListDto) {
        return articleService.findListByLabelIdOrCategoryId(articleListDto);
    }
}
